package io.jnet.common.readprocessor;

import com.jfireframework.baseutil.collection.buffer.ByteBuf;
import io.jnet.common.api.ChannelContext;
import io.jnet.common.api.ReadProcessor;
import io.jnet.common.bufstorage.BufStorage;
import io.jnet.common.streamprocessor.ProcesserUtil;
import io.jnet.common.streamprocessor.StreamProcessor;

public class SimpleReadProcessor implements ReadProcessor
{
    
    @Override
    public void process(ByteBuf<?> buf, BufStorage bufStorage, StreamProcessor[] inProcessors, ChannelContext channelContext) throws Throwable
    {
        Object finalResult = ProcesserUtil.process(channelContext, inProcessors, buf, 0);
        if (finalResult instanceof ByteBuf<?>)
        {
            bufStorage.putBuf(buf);
            channelContext.registerWrite();
        }
    }
}
